package org.xx.armory.web.tags;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.jsp.JspException;

public final class HtmlLink extends BaseHtmlTagHandler {
    private static final long serialVersionUID = 1L;
    private static final String DEFAULT_HREF = "#";
    private String href = "#";
    private String target = "";

    public HtmlLink() {
    }

    public final String getHref() {
        return this.href;
    }

    public final void setHref(String value) {
        this.href = StringUtils.trimToEmpty(value);
        if (this.href.isEmpty()) {
            this.href = "#";
        }

    }

    public final String getTarget() {
        return this.target;
    }

    public void setTarget(String value) {
        this.target = StringUtils.trimToEmpty(value);
    }

    public int doStartTag()
            throws JspException {
        if (!this.getHref().isEmpty()) {
            String src = TagUtils.evalRelUrl(this.pageContext, this.getHref());
            this.setValue("href", src);
        }

        if (!this.getTarget().isEmpty()) {
            this.setValue("target", this.getTarget());
        }

        super.doStartTag();
        return 1;
    }

    protected String getTagName() {
        return "a";
    }

    protected boolean isEmptyContent() {
        return false;
    }
}
